package com.yc.fav;

import com.google.gson.Gson;
import com.yc.fav.service.BizException;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Company 源辰信息
 *
 * @author navy
 * @date 2024/8/5
 * Email haijunzhou@hnit.edu.cn
 */
public class Utils {

    public static void check(boolean bool, String msg) throws BizException{
        if(bool){
            throw new BizException(msg);
        }
    }

    public static void checkEmpty(Object object, String msg) throws BizException{
        check(object == null ||
                object instanceof String && ((String) object).isBlank(), msg);
    }

    public static void print(HttpServletResponse resp, Object object) throws IOException {
        Gson gson = new Gson();
        String json = gson.toJson(object);
        resp.setContentType("application/json;charset=utf-8");
        resp.getWriter().println(json);
    }

}
